package com.video.web.controller.system;

import java.util.List;

import com.video.system.domain.VideoTeacherTitle;
import com.video.system.service.IVideoTeacherTitleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.video.common.annotation.Log;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.enums.BusinessType;
import com.video.system.domain.VideoTeacher;
import com.video.system.service.IVideoTeacherService;
import com.video.common.utils.poi.ExcelUtil;
import com.video.common.core.page.TableDataInfo;

/**
 * 教师Controller
 * 
 * @author lyh
 * @date 2021-07-31
 */
@RestController
@RequestMapping("/system/teacher")
public class VideoTeacherController extends BaseController
{
    @Autowired
    private IVideoTeacherService videoTeacherService;
    @Autowired
    private IVideoTeacherTitleService videoTeacherTitleService;

    /**
     * 查询教师列表
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(VideoTeacher videoTeacher)
    {
        startPage();
        List<VideoTeacher> list = videoTeacherService.selectVideoTeacherList(videoTeacher);
        return getDataTable(list);
    }

    /**
     * 导出教师列表
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:export')")
    @Log(title = "教师", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VideoTeacher videoTeacher)
    {
        List<VideoTeacher> list = videoTeacherService.selectVideoTeacherList(videoTeacher);
        ExcelUtil<VideoTeacher> util = new ExcelUtil<VideoTeacher>(VideoTeacher.class);
        return util.exportExcel(list, "教师数据");
    }

    /**
     * 获取教师详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:query')")
    @GetMapping(value = {"/","/{teacherId}"})
    public AjaxResult getInfo(@PathVariable(value = "teacherId", required = false) Integer teacherId)
    {
        AjaxResult ajax = AjaxResult.success(videoTeacherService.selectVideoTeacherById(teacherId));
        List<VideoTeacherTitle> videoTeacherTitles = videoTeacherTitleService.selectCodeAndNameList();
        ajax.put("titles",videoTeacherTitles);
        System.out.println("=============================>"+ajax);
        return ajax;

        //return AjaxResult.success(videoTeacherService.selectVideoTeacherById(teacherId));
    }

    /**
     * 新增教师
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:add')")
    @Log(title = "教师", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoTeacher videoTeacher)
    {
        return toAjax(videoTeacherService.insertVideoTeacher(videoTeacher));
    }

    /**
     * 修改教师
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:edit')")
    @Log(title = "教师", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoTeacher videoTeacher)
    {
        return toAjax(videoTeacherService.updateVideoTeacher(videoTeacher));
    }

    /**
     * 删除教师
     */
    @PreAuthorize("@ss.hasPermi('system:teacher:remove')")
    @Log(title = "教师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable Integer[] teacherIds)
    {
        return toAjax(videoTeacherService.deleteVideoTeacherByIds(teacherIds));
    }
}
